package com.carleasoft.mps.cms.business.process.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.cms.business.process.bean.entity.BaseProcessModuleEntity;
import com.carleasoft.mps.cms.business.process.bean.po.*;
import com.carleasoft.mps.cms.business.process.bean.vo.GetProcessInfoVo;
import com.carleasoft.mps.cms.business.process.bean.vo.MyApprovalPageReportVo;
import com.carleasoft.mps.cms.business.process.bean.vo.MyApprovalPageVo;
import com.carleasoft.mps.cms.business.process.service.BaseProcessNodeRelService;
import com.carleasoft.mps.cms.business.train.bean.vo.TrainCarVo;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.user.ThreadUserContext;
import com.carleasoft.mps.core.user.UserCacheData;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 流程模型
 *
 * @author: yangHao
 * @createDate:2023/6/2
 * @description:
 */
@RestController
@RequestMapping("/node")
public class BaseProcessModuleController {


    @Autowired
    private BaseProcessNodeRelService baseProcessNodeRelService;

    /**
     * 添加/修改 审批模板
     *
     * @param nodePo
     * @return
     */
    @PostMapping("/saveNode")
    public R saveNode(@RequestBody NodePo nodePo) {
        IBeanUtil.paramVerify(nodePo, "type", "moduleName", "baseNodePos");
        boolean isOk = baseProcessNodeRelService.saveNode(nodePo);
        return R.ok(isOk);
    }

    /**
     * 分页
     *
     * @param nodePo
     * @return
     */
    @PostMapping("/pageQuery")
    public R pageQuery(@RequestBody NodePo nodePo) {
        IBeanUtil.paramVerify(nodePo, "current", "size");
        Page<BaseProcessModuleEntity> baseProcessModuleEntityPage = baseProcessNodeRelService.pageQuery(new Page(nodePo.getCurrent(), nodePo.getSize()), nodePo);
        return R.ok(baseProcessModuleEntityPage);
    }

    /**
     * 详情
     *
     * @param nodePo
     * @return
     */
    @PostMapping("/detail")
    public R detail(@RequestBody NodePo nodePo) {
        IBeanUtil.paramVerify(nodePo, "moduleCode");
        NodePo baseNodePos = baseProcessNodeRelService.detail(nodePo);
        return R.ok(baseNodePos);
    }

    /**
     * 根据模板类型获取节点人员
     *
     * @param nodePo
     * @return
     */
    @PostMapping("/getModuleInfo")
    public R getModuleInfo(@RequestBody NodePo nodePo) {
        IBeanUtil.paramVerify(nodePo, "type");
        NodePo baseNodePos = baseProcessNodeRelService.getModuleInfo(nodePo);
        return R.ok(baseNodePos);
    }


    /**
     * 提交审批
     *
     * @param nodePo
     * @return
     */
    @PostMapping("/submitApproval")
    public R submitApproval(@RequestBody NodePo nodePo) {
        boolean isOk = baseProcessNodeRelService.submitApproval(nodePo);
        return R.ok(isOk);
    }

    /**
     * 审批-分页 请假的
     *
     * @param myApprovalPagePo
     * @return
     */
    @PostMapping("/myApprovalPage")
    public R myApprovalPage(@RequestBody MyApprovalPagePo myApprovalPagePo) {
        Page<MyApprovalPageVo> myApprovalPageVoPage = baseProcessNodeRelService.myApprovalPage(new Page(myApprovalPagePo.getCurrent(), myApprovalPagePo.getSize()), myApprovalPagePo);
        return R.ok(myApprovalPageVoPage);
    }


    /**
     * 审批-分页 销假的
     *
     * @param myApprovalPagePo
     * @return
     */
    @PostMapping("/myApprovalPageReport")
    public R myApprovalPageReport(@RequestBody MyApprovalPagePo myApprovalPagePo) {
        Page<MyApprovalPageReportVo> myApprovalPageVoPage = baseProcessNodeRelService.myApprovalPageReport(new Page(myApprovalPagePo.getCurrent(), myApprovalPagePo.getSize()), myApprovalPagePo);
        return R.ok(myApprovalPageVoPage);
    }

    /**
     * 审批-分页  报车用车
     *
     * @param myApprovalPageCarPo
     * @return
     */
    @PostMapping("/myApprovalPageCar")
    public R myApprovalPageCar(@RequestBody MyApprovalPageCarPo myApprovalPageCarPo) {
        Page<TrainCarVo> trainCarVoPage = baseProcessNodeRelService.myApprovalPageCar(new Page(myApprovalPageCarPo.getCurrent(), myApprovalPageCarPo.getSize()), myApprovalPageCarPo);
        return R.ok(trainCarVoPage);
    }

    /**
     * 审批-分页  当前登录人报车用车
     *
     * @param myApprovalPageCarPo
     * @return
     */
    @PostMapping("/currentLogonPageCar")
    public R currentLogonPageCar(@RequestBody MyApprovalPageCarPo myApprovalPageCarPo) {
        // 获取当前登录人信息
        UserCacheData userInfo = ThreadUserContext.getCurrentCacheUser();
        myApprovalPageCarPo.setCreatePersonCode(userInfo.getUserCode());
        Page<TrainCarVo> trainCarVoPage = baseProcessNodeRelService.myApprovalPageCar(new Page(myApprovalPageCarPo.getCurrent(), myApprovalPageCarPo.getSize()), myApprovalPageCarPo);
        return R.ok(trainCarVoPage);
    }

    /**
     * 审批
     * @param checkPo
     * @return
     */
    @PostMapping("/check")
    public R check(@RequestBody CheckPo checkPo) {
        Integer isOk = baseProcessNodeRelService.check(checkPo);
        return R.ok(isOk);
    }

    /**
     * 审批流程查询
     * @param getProcessInfoPo
     * @return
     */
    @PostMapping("/getProcessInfo")
    public R getProcessInfo(@RequestBody GetProcessInfoPo getProcessInfoPo){
        IBeanUtil.paramVerify(getProcessInfoPo,"bisCode");
        GetProcessInfoVo getProcessInfoVo=baseProcessNodeRelService.getProcessInfo(getProcessInfoPo);
        return R.ok(getProcessInfoVo);
    }


}
